/*
 * Copyright (C) 2014 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * Purpose : Definition of ME handler: ZTE_SNTP (65294)
 *
 * Feature : The file includes the following modules and sub-modules
 *           (1) ME handler: ZTE_SNTP (65294)
 *           (2) re-write file /tmp/ntp_date_time.conf and send event to notify systemd
 *               The format of /tmp/ntp_date_time.conf as below
 *               ENABLE_NTP_SERVER=0
 *               DATE=092205352016
 *               TIME_ZONE=i
 *               MASTER_SERVER=10.40.8.18
 *               SLAVE_SERVER=10.40.8.18
 *               INTERVAL=3600
 */

#include "app_basic.h"


MIB_TABLE_INFO_T gMibZteSntpTableInfo;
MIB_ATTR_INFO_T  gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR_NUM];
MIB_TABLE_ZTESNTP_T gMibZteSntpDefRow;
MIB_TABLE_OPER_T  gMibZteSntpOper;

GOS_ERROR_CODE omci_zte_sntp_oper_reset(UINT32 args_num, ...)
{
    MIB_TABLE_ZTESNTP_T   meZteSntp;

    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: ZteSntp");

    remove(OMCI_NTP_DATE_TIME_CONF);

    remove(OMCI_NTP_DATE_TIME_TMP_CONF);

    MIB_Default(MIB_TABLE_ZTESNTP_INDEX, &meZteSntp, sizeof(MIB_TABLE_ZTESNTP_T));

    meZteSntp.EntityID = 0;

    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_ZTESNTP_INDEX, &meZteSntp, sizeof(MIB_TABLE_ZTESNTP_T)));

    OMCI_MeOperCfg(MIB_TABLE_ZTESNTP_INDEX, NULL, &meZteSntp, MIB_ADD,
                   omci_GetOltAccAttrSet(MIB_TABLE_ZTESNTP_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);

    return GOS_OK;
}


GOS_ERROR_CODE ZteSntpDrvCfg(void             *pOldRow,
                            void            *pNewRow,
                            MIB_OPERA_TYPE  operationType,
                            MIB_ATTRS_SET   attrSet,
                            UINT32          pri)
{
	MIB_TABLE_ZTESNTP_T     *pMibZteSntp = NULL, *pOldMibZteSntp = NULL;
    FILE                    *fp = NULL;
    UINT32                  strLen;
    omci_event_msg_t        omciEventMsg;

	pMibZteSntp = (MIB_TABLE_ZTESNTP_T *)pNewRow;
    pOldMibZteSntp = (MIB_TABLE_ZTESNTP_T *)pOldRow;

    OMCI_LOG(OMCI_LOG_LEVEL_DBG, "Start %s...", __FUNCTION__);

    switch (operationType)
    {
    case MIB_SET:
    	OMCI_LOG(OMCI_LOG_LEVEL_DBG,"ZTE SNTP --> SET");

        if (access("OMCI_NTP_DATE_TIME_CONF", 0) < 0)
        {
            // doesn't exist

            if (!(fp = fopen (OMCI_NTP_DATE_TIME_CONF, "w")))
            {
                OMCI_LOG(OMCI_LOG_LEVEL_ERR, "%s():%d fopen %s failed",
                    __FUNCTION__, __LINE__, OMCI_NTP_DATE_TIME_CONF);
                return GOS_FAIL;
            }
            fprintf(fp, "%s", "ENABLE_NTP_SERVER=1\n");

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ZTESNTP_TIMEZONE_INDEX) &&
                pMibZteSntp->TimeZone != pOldMibZteSntp->TimeZone)
            {
                double num;
                if (((pMibZteSntp->TimeZone) >> 15) & 0x1)
                {
                    // is negative
                    num = (0x10000 - pMibZteSntp->TimeZone);
                    fprintf(fp, "TIME_ZONE=-%.1f\n", num / 60);

                }
                else
                {
                    num = pMibZteSntp->TimeZone;
                    fprintf(fp, "TIME_ZONE=+%.1f\n", num / 60);
                }
            }

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX) &&
                pMibZteSntp->MasterServer != pOldMibZteSntp->MasterServer)
            {
                fprintf(fp, "MASTER_SERVER="IPADDR_PRINT"\n", IPADDR_PRINT_ARG(pMibZteSntp->MasterServer));
            }

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX) &&
                pMibZteSntp->SlaveServer != pOldMibZteSntp->SlaveServer)
            {
                fprintf(fp, "SLAVE_SERVER="IPADDR_PRINT"\n", IPADDR_PRINT_ARG(pMibZteSntp->SlaveServer));
            }

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ZTESNTP_INTERVAL_INDEX) &&
                pMibZteSntp->Interval != pOldMibZteSntp->Interval)
            {
                fprintf(fp, "INTERVAL=%u\n", pMibZteSntp->Interval);
            }

            fclose(fp);
        }
        else
        {
            if (GOS_OK != omci_util_ntp_conf_replace_opt_val("ENABLE_NTP_SERVER", "=1"))
            {
                OMCI_LOG(OMCI_LOG_LEVEL_ERR,
                    "%s()%d: Failed to replace option value of ntp conf",
                    __FUNCTION__, __LINE__);
                return GOS_FAIL;
            }

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ZTESNTP_TIMEZONE_INDEX) &&
                pMibZteSntp->TimeZone != pOldMibZteSntp->TimeZone)
            {
                CHAR *pStr = NULL;
                double num;
                if ((pMibZteSntp->TimeZone >> 15) & 0x1)
                {
                    num = (0x10000 - pMibZteSntp->TimeZone);
                    strLen = snprintf(NULL, 0, "=-%.1f", num / 60);
                    pStr = (CHAR *)malloc(strLen + 1);
                    snprintf(pStr, strLen + 1, "=-%.1f", num / 60);
                }
                else
                {
                    num = pMibZteSntp->TimeZone;;
                    strLen = snprintf(NULL, 0, "=+%.1f", num / 60);
                    pStr = (CHAR *)malloc(strLen + 1);
                    snprintf(pStr, strLen + 1, "=+%.1f", num / 60);
                }

                if (GOS_OK != omci_util_ntp_conf_replace_opt_val("TIME_ZONE", pStr))
                {
                    OMCI_LOG(OMCI_LOG_LEVEL_ERR,
                        "%s()%d: Failed to replace option value of ntp conf",
                        __FUNCTION__, __LINE__);
                    free(pStr);
                    return GOS_FAIL;
                }
                free(pStr);
            }

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX) &&
                pMibZteSntp->MasterServer != pOldMibZteSntp->MasterServer)
            {
                CHAR *pStr = NULL;
                strLen = snprintf(NULL, 0, "="IPADDR_PRINT, IPADDR_PRINT_ARG(pMibZteSntp->MasterServer));
                pStr = (CHAR *)malloc(strLen + 1);
                snprintf(pStr, strLen + 1, "="IPADDR_PRINT, IPADDR_PRINT_ARG(pMibZteSntp->MasterServer));
                if (GOS_OK != omci_util_ntp_conf_replace_opt_val("MASTER_SERVER", pStr))
                {
                    OMCI_LOG(OMCI_LOG_LEVEL_ERR,
                        "%s()%d: Failed to replace option value of ntp conf",
                        __FUNCTION__, __LINE__);
                    free(pStr);
                    return GOS_FAIL;
                }
                free(pStr);
            }

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX) &&
                pMibZteSntp->SlaveServer != pOldMibZteSntp->SlaveServer)
            {
                CHAR *pStr = NULL;
                strLen = snprintf(NULL, 0, "="IPADDR_PRINT, IPADDR_PRINT_ARG(pMibZteSntp->SlaveServer));
                pStr = (CHAR *)malloc(strLen + 1);
                snprintf(pStr, strLen + 1, "="IPADDR_PRINT, IPADDR_PRINT_ARG(pMibZteSntp->SlaveServer));
                if (GOS_OK != omci_util_ntp_conf_replace_opt_val("SLAVE_SERVER", pStr))
                {
                    OMCI_LOG(OMCI_LOG_LEVEL_ERR,
                        "%s()%d: Failed to replace option value of ntp conf",
                        __FUNCTION__, __LINE__);
                    free(pStr);
                    return GOS_FAIL;
                }
                free(pStr);
            }

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ZTESNTP_INTERVAL_INDEX) &&
                pMibZteSntp->Interval != pOldMibZteSntp->Interval)
            {
                CHAR *pStr = NULL;
                strLen = snprintf(NULL, 0, "=%u", pMibZteSntp->Interval);
                pStr = (CHAR *)malloc(strLen + 1);
                snprintf(pStr, strLen + 1, "=%u", pMibZteSntp->Interval);
                if (GOS_OK != omci_util_ntp_conf_replace_opt_val("INTERVAL", pStr))
                {
                    OMCI_LOG(OMCI_LOG_LEVEL_ERR,
                        "%s()%d: Failed to replace option value of ntp conf",
                        __FUNCTION__, __LINE__);
                    free(pStr);
                    return GOS_FAIL;
                }
                free(pStr);
            }

        }

        // send notification
        memset(&omciEventMsg, 0, sizeof(omci_event_msg_t));
        omciEventMsg.subType = OMCI_EVENT_TYPE_NTP_DATETIME;
        omciEventMsg.status = 1;

        if (GOS_OK != omci_wrapper_sendOmciEvent(&omciEventMsg))
        {
            OMCI_LOG(OMCI_LOG_LEVEL_ERR, "Send ntp event fail");
        }

    	break;
    default:
        break;
    }

	return GOS_OK;
}


GOS_ERROR_CODE mibTable_init(MIB_TABLE_INDEX tableId)
{
    UINT8 proprietary_mib_cb_bitmask = 0;
    UINT8 isIgnore = 0;
    if(GOS_OK == omci_ignore_mib_table_check(OMCI_ME_CLASS_SNTP, OMCI_ME_CLASS_SUB_DEFAULT, &isIgnore))
    {
        if(isIgnore)
        {
            OMCI_PRINT("Ignore classId:%d", OMCI_ME_CLASS_SNTP);
            return GOS_FAIL;
        }
    }

    gMibZteSntpTableInfo.Name = "ZteSntp";
    gMibZteSntpTableInfo.ShortName = "ZTESNTP";
    gMibZteSntpTableInfo.Desc = "Zte-sntp";
    gMibZteSntpTableInfo.ClassId = (UINT32)(OMCI_ME_CLASS_SNTP);
    gMibZteSntpTableInfo.InitType = (UINT32)(OMCI_ME_INIT_TYPE_ONU);
    gMibZteSntpTableInfo.StdType = (UINT32)(OMCI_ME_TYPE_PROPRIETARY);
    gMibZteSntpTableInfo.ActionType = (UINT32)(OMCI_ME_ACTION_SET | OMCI_ME_ACTION_GET);
    gMibZteSntpTableInfo.pAttributes = &(gMibZteSntpAttrInfo[0]);
	gMibZteSntpTableInfo.attrNum = MIB_TABLE_ZTESNTP_ATTR_NUM;
	gMibZteSntpTableInfo.entrySize = sizeof(MIB_TABLE_ZTESNTP_T);
	gMibZteSntpTableInfo.pDefaultRow = &gMibZteSntpDefRow;

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "EntityID";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "TZ";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].Name = "MasterServer";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].Name = "SlaveServer";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].Name = "InterVal";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].Name = "Unknown";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].Name = "Unknown";

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Entity ID";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Time Zone";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Master Server";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Slave Server";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "InterVal";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Unknown";
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Unknown";

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT32;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT32;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT32;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].Len = 4;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].Len = 4;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].Len = 4;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = TRUE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;

    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_TIMEZONE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_MASTERSERVER_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_SLAVESERVER_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_INTERVAL_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR6_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibZteSntpAttrInfo[MIB_TABLE_ZTESNTP_ATTR7_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;

    memset(&(gMibZteSntpDefRow), 0x00, sizeof(gMibZteSntpDefRow));
    memset(&gMibZteSntpOper, 0x0, sizeof(MIB_TABLE_OPER_T));
	gMibZteSntpOper.meOperDrvCfg = ZteSntpDrvCfg;
	gMibZteSntpOper.meOperDump = omci_mib_oper_dump_default_handler;
    gMibZteSntpOper.meOperCb[PROPRIETARY_MIB_CB_RESET] = omci_zte_sntp_oper_reset;
	MIB_TABLE_ZTESNTP_INDEX = tableId;
	MIB_InfoRegister(tableId,&gMibZteSntpTableInfo,&gMibZteSntpOper);
    proprietary_mib_cb_bitmask = (1 << PROPRIETARY_MIB_CB_RESET);
    MIB_Proprietary_Reg(tableId, proprietary_mib_cb_bitmask);

    return GOS_OK;
}
